﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Interfaces;
using Cofe.Core.Property;

namespace Cofe.Core.Implements
{
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_NONE + 5)]
    class ParsePathPrimaryPPRegenerator : IEntryPrimaryPPRegenerator
    {
        public async Task<IPropertyProvider> RegenerateAsync(IPropertyCache propertyCache)
        {
            string fullName = propertyCache.GetOneProperty<string>(CofeProperties.FullParseName);
            Console.WriteLine("Connecting " + fullName);
            var ph = await CofeServices.PathParserManager.Behaviors.TryParsePathAsync(fullName,
                ParsableType.ParsePathLookup, EntryConstructionFlags.DefaultWithoutCacheWithLookup);

            if (ph != null && ph.PrimaryPropertyProvider != null)
                return ph.PrimaryPropertyProvider;
            else return null;
        }
    }
}
